<!-- 模板审核弹窗 -->
<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="800">
    <el-radio-group v-model="activeTab">
      <el-radio-button value="1">合同审核</el-radio-button>
      <el-radio-button value="2">审核日志</el-radio-button>
    </el-radio-group>
    <!-- 审核信息 -->
    <div v-show="activeTab === '1'">
      <div class="review-container" style="height: 500px;">

      </div>
      <el-form-item label="审核备注" required>
        <el-input v-model="remark" placeholder="若审核不通过，请填写不通过原因" type="textarea"  />
      </el-form-item>
    </div>
    <!-- 审核日志  -->
    <div v-show="activeTab === '2'">
      <div v-if="reviewRecord.length"></div>
      <el-empty v-else description="暂无审核日志" />
    </div>
    <template #footer v-if="activeTab === '1'">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="danger" @click="handleReview(0)">审核不通过</el-button>
      <el-button type="primary" @click="handleReview(1)">审核通过</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
import {ElMessage} from 'element-plus'
import { operatorLog,tplReview } from '@/api/contract/tplReview'
const message = useMessage() // 消息弹窗
const dialogTitle = ref('模板审核')
const dialogVisible = ref(false)  
const activeTab = ref('1')
const remark = ref('')  /// 审核备注
const reviewRecord = ref([])
const tplNo = ref('')
function open(_tplNo: string) {
  dialogVisible.value = true
  tplNo.value = _tplNo
  getTplReviewRecord(_tplNo)
}

function close() {
  dialogVisible.value = false
} 

// 获取模板审核记录
const getTplReviewRecord = async (tplNo: string) => { 
  const params = {
    pageNo: 1,
    pageSize: 10,
    ctrNo: tplNo,
  }
  const res = await operatorLog(params)
  if (res.code === 0) {
  }
}
// 模板审核
const handleReview = async (status: number) => { 
  if(status == 0 && !remark.value) {
    ElMessage.error('请填写审核意见')
    return
  }
  await message.confirm('确认提交吗？')
  const params = {
    tplNo: tplNo.value,
    reviewStatus: status,
    remark: remark.value,
  }
  console.log(params)
  const res = await tplReview(params)
  if (res.code === 0) {
    ElMessage.success('操作成功')
    close()
  }
}

defineExpose({
  open,
})  
</script>
<style lang="scss" scoped> 

</style>
